#!/bin/bash
# 明确工作环境
DIR_NAME=$(dirname "$0")
BASE_PATH=$(cd "$DIR_NAME" || exit; pwd)
cd "$BASE_PATH" || exit
# GPG 密码
GPG_PASSWORD=$(cat ./passphrase.txt)
# 打包新文件
mvn -q clean package source:jar javadoc:jar -D"maven.test.skip"=true
# MAVEN仓库签署
mvn -q gpg:sign-and-deploy-file \
-D"pomFile"=./pom.xml \
-D"repositoryId"=ossrh \
-D"url"=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ \
-D"file"=./target/ztc-tools-0.0.1.jar

mvn -q gpg:sign-and-deploy-file \
-D"pomFile"=./pom.xml \
-D"repositoryId"=ossrh \
-D"url"=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ \
-D"file"=./target/ztc-tools-0.0.1-sources.jar \
-D"classifier"=sources

mvn -q gpg:sign-and-deploy-file \
-D"pomFile"=./pom.xml \
-D"repositoryId"=ossrh \
-D"url"=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ \
-D"file"=./target/ztc-tools-0.0.1-javadoc.jar \
-D"classifier"=javadoc
# 初始化工作目录
WORKING_DIRECTORY=".publish"
rm -rf ./$WORKING_DIRECTORY && mkdir ./$WORKING_DIRECTORY && cd ./$WORKING_DIRECTORY || exit
# 移动新文件
cp ../pom.xml ./
cp ../target/ztc-tools-0.0.1.jar ./
cp ../target/ztc-tools-0.0.1-javadoc.jar ./
cp ../target/ztc-tools-0.0.1-sources.jar ./
# 签名
gpg -ab --pinentry-mode loopback --batch --passphrase "$GPG_PASSWORD" ./pom.xml
gpg -ab --pinentry-mode loopback --batch --passphrase "$GPG_PASSWORD" ./ztc-tools-0.0.1.jar
gpg -ab --pinentry-mode loopback --batch --passphrase "$GPG_PASSWORD" ./ztc-tools-0.0.1-javadoc.jar
gpg -ab --pinentry-mode loopback --batch --passphrase "$GPG_PASSWORD" ./ztc-tools-0.0.1-sources.jar
# 验证签名
gpg --verify ./pom.xml.asc
gpg --verify ./ztc-tools-0.0.1.jar.asc
gpg --verify ./ztc-tools-0.0.1-javadoc.jar.asc
gpg --verify ./ztc-tools-0.0.1-sources.jar.asc
# 压缩打包
jar -cvf bundle.jar ./